package 剑指offer;

import leetcode.day_2020_12_14_12_21.TreeNode;

public class Offer28_JZ58 {
    boolean isSymmetrical(TreeNode pRoot) {
        return subIsSymmetrical(pRoot, pRoot);
    }

    public boolean subIsSymmetrical(TreeNode pRoot1, TreeNode pRoot2) {
        if (pRoot1==null && pRoot2==null) {
            return true;
        }
        if (pRoot1==null || pRoot2==null) {
            return false;
        }
        if (pRoot1.val != pRoot2.val) {
            return false;
        }
        return subIsSymmetrical(pRoot1.left, pRoot2.right) && subIsSymmetrical(pRoot1.right, pRoot2.left);
    }
}
